package com.lanhao.aot.fastjson;

import com.alibaba.fastjson.JSON;

public class Result<T> {
	protected String code;
	protected String message;
	protected T value;

	public Result() {
	}

	public Result(String code, String message) {
		this.code = code;
		this.message = message;
	}

	public Result(String code, String message, T value) {
		this.code = code;
		this.message = message;
		this.value = value;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public static <T> Result<T> ok() {
		return new Result<T>("0000", "成功");
	}

	public static <T> Result<T> ok(String message) {
		return new Result<T>("0000", message);
	}

	public static <T> Result<T> fail() {
		return new Result<T>("0001", "失败");
	}

	public static <T> Result<T> fail(String message) {
		return new Result<T>("0001", message);
	}

	public static <T> Result<T> tokenFail(String message) {
		return new Result<T>("0009", message);
	}

	public static <T> Result<T> result(String code, String message) {
		return new Result<T>(code, message);
	}

	public T getValue() {
		return value;
	}

	public void setValue(T value) {
		this.value = value;
	}

	@Override
	public String toString() {
		return JSON.toJSONString(this);
	}

}
